<?php
/**
 * Created by PhpStorm.
 * User: zhouyao
 * Date: 2017/10/10
 * Time: 下午4:11
 */
namespace App\Http\Controllers;

use HuangYi\Rbac\Managers\RoleManager;

class RoleController extends Controller
{
    protected $roleManager;

    public function __construct(RoleManager $roleManager)
    {
        $this->roleManager = $roleManager;
    }

    public function store()
    {
        $role = $this->roleManager->create([
            'name' => 'Administrator',
            'slug' => 'admin',
            'description' => 'Can do anything'
        ]);
        dd($role);
    }

    public function destroy($id)
    {
        $deleted = $this->roleManager->delete($id);

        dd($deleted);
    }

    public function show($id)
    {
        $role = $this->roleManager->find($id);

        dd($role);
    }


    /**
     * 为角色绑定权限
     * @param $id
     */
    public function attachPermission($id)
    {
        $this->roleManager->attachPermissions($id); //如需绑定多个直接传数组即可
    }
}